﻿using SharedClassLibrary;
using SharedClassLibrary.Contracts;
using SharedClassLibrary.DTOs;
using System.Net.Http.Json;

namespace BlazorWebAssemblyDemo.Services
{
    public class UserService : IUserService
    {
        private readonly HttpClient httpClient;
        private const string baseUrl = "http://localhost:5029";

        public UserService(HttpClient httpClient)
        {
            this.httpClient = httpClient;
        }

        public Task<GeneralResponse> CreateAccountAsync(UserDTO userDTO)
        {
            throw new NotImplementedException();

        }

        public async Task<LoginResponse> LoginAsync(LoginDTO loginDTO)
        {
            var response = await httpClient.PostAsync($"/login", Generics.GenerateStringContent(Generics.SerializeObject(loginDTO)));
            var returnObject = await response.Content.ReadAsStringAsync();
            return Generics.DeserializeJsonString<LoginResponse>(returnObject);
        }
    }
}
